package com.abel.bigwater.dataserver.model.hgd

import com.abel.bigwater.data.BcdString
import com.abel.bigwater.dataserver.model.PacketException
import io.netty.buffer.ByteBuf

class HgdaoTcpUnknown : HgdaoBase {

    constructor() : super(HgdaoBase.TYPE_TCP)

    /**
     * @param type
     */
    constructor(type: String) : super(type)

    /**
     * Just consume all bytes, return true always.
     *
     * 53 54 3A 31 30 30 30 30 3B 31 36 2F 30 39 2F 30 38 20 32 33 3A 35 30 3B 50 31 3A 30 30 30 30 30 30 30 30 30 3B 50
     * 32 3A 30 30 30 30 30 30 30 30 30 3B 4B 33 3A 31 3B 4B 34 3A 31 3B 41 31 3A 30 2E 30 30 30 3B 41 32 3A 30 2E 30 30
     * 30 3B 48 3A 30 30 32 3B 53 3A 32 33 2E 0D 0A
     *
     * 32 32 3A 31 30 30 30 30 0D 0A 40 32 32 32 3A 31 30 30 30 30 0D 0A 53 54 3A 31 30 30 30 30 3B 31 36 2F 30 39 2F 30
     * 39 20 30 30 3A 30 30 3B 50 31 3A 30 30 30 30 30 30 30 30 30 3B 50 32 3A 30 30 30 30 30 30 30 30 30 3B 4B 33 3A 31
     * 3B 4B 34 3A 31 3B 41 31 3A 30 2E 30 30 30 3B 41 32 3A 30 2E 30 30 30 3B 48 3A 30 30 31 3B 53 3A 32 34 2E 0D 0A
     *
     * @222:10000
     * ST:10000;16/09/09 00:00;P1:000000000;P2:000000000;K3:1;K4:1;A1:0.000;A2:0.000;H:001;S:24.
     *
     * @param buf
     * @return
     * @throws PacketException
     */
    @Throws(PacketException::class)
    override fun parseBuffer(buf: ByteBuf, ignoreChecksum: Boolean): Boolean {
        fmt = BcdString.hexString(buf)
        temp = ByteArray(buf.readableBytes()).also { buf.readBytes(it) }

        return true
    }

    /* (non-Javadoc)
     * @see java.lang.Object#toString()
     */
    override fun toString(): String {
        return String.format("HgdaoTcpUnknown[abbr=%s, buf=%s]", type, fmt)
    }

    companion object {
        private val MAX_LENGTH: Short = 1024
    }

}
